import { App } from 'vue'

export default function registerComponent(app: App) {
	try {
		const files = require.context('@/components', true, /\.(vue|tsx)$/)

		files.keys().forEach((fileName) => {
			const componentConfig = files(fileName)
			// const regRes = fileName.match(/(?<=\/).*?(?=\/)/)  // 微信浏览器或手机端 匹配失败
			const regRes = fileName.match(/\/.*?\//)

			if (regRes) {
				const name = regRes[0].replace(/\//g, '')
				app.component(name, componentConfig.default)
			}
		})
	} catch (error) {
		console.log('注册组件失败')
	}
}
